package com.situ.orderingsystem.service.impl;

import com.situ.orderingsystem.dao.EmployeeDao;
import com.situ.orderingsystem.dao.impl.EmployeeDaoImpl;
import com.situ.orderingsystem.model.Employee;
import com.situ.orderingsystem.model.EmployeeSerchBean;
import com.situ.orderingsystem.service.EmpoloyeeService;
import com.situ.orderingsystem.utils.BeanFactory;
import com.situ.orderingsystem.utils.PaginateInfo;

import java.util.List;

public class EmployeeServiceImpl implements EmpoloyeeService {
    private final EmployeeDao dao = BeanFactory.getBean(EmployeeDaoImpl.class);
    @Override
    public List<Employee> findAll(EmployeeSerchBean eb, PaginateInfo pi) {

        return dao.findAll(eb,pi);
    }
    public List<Employee> findAll2() {

        return dao.findAll2();
    }
    @Override
    public int deleteByIds(Integer[] ids) {
        int rows=0;
        for(Integer id :ids){
            boolean b = dao.deleteById(id) ;
           if(b){
               rows++;
           }
        }
        return  rows;
    }

    @Override
    public boolean save(Employee employee) {
         return  dao.add(employee) > 0;
    }

    @Override
    public Employee searchById(Integer id) {
        return  dao.searchById(id);
    }

    @Override
    public boolean update(Employee employee) {
        return dao.update(employee)  > 0;
    }
}

